package main

import "fmt"

/*
   Author: mahaiyuan
   Date: 2021/5/29 2:09 下午
   Description:
*/
func main() {
	ch := make(chan int)
	go func() {
		for i := 0; i < 10; i++ {
			ch <- i + 1
		}
		close(ch)	//不再需要向管道里存数据，需要关闭通道
	}()
	/*for true {
		if data, ok := <- ch; ok {
			fmt.Println("data =", data)
		} else {
			break
		}
	}*/
	for val := range ch {	//关闭通道后会退出for range循环
		fmt.Println("data =", val)
	}
	fmt.Println("main finish")
}